package scu.maqiang.possion;

import java.util.Arrays;

import scu.maqiang.fes.BVPType;
import scu.maqiang.fes.FES1L21;
import scu.maqiang.mesh.Mesh1L2;
import scu.maqiang.mesh.ScalarFunc;
import scu.maqiang.numeric.NewIterSSolver;
import scu.maqiang.numeric.SRMatrix;

/**
 * 一维L2投影
*/
public class L2Project1D {

	public static void main(String[] args) {
		Mesh1L2 mesh = new Mesh1L2();
		mesh.line(0, 1, 5);
		FES1L21 fs = new FES1L21(mesh);
		SRMatrix M = new SRMatrix(fs.GetNdof());
		double[] RHS = new double[fs.GetNdof()];
		double[] x = new double[fs.GetNdof()];
		fs.assembleMass(new double[] {1.0}, BVPType.LUMP_MASS, M);
		M.sort();
		System.out.println(M);
		ScalarFunc Foo1 = (xy, label, param) -> 2 * xy[0] * Math.sin(2 * Math.PI * xy[0]) + 3;
		fs.assembleSource(new ScalarFunc[] {Foo1}, null, BVPType.COMMON, RHS);
		System.out.println(Arrays.toString(RHS));
		NewIterSSolver solver = new NewIterSSolver(M);
		solver.CG(RHS, x, 1);
		System.out.println(Arrays.toString(x));
	}
}
